package cn.com.sinux.spring.repositories;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.NoRepositoryBean;

import java.io.Serializable;

/**
 * Repository扩展接口类
 * <p/>
 * Created:14-7-3 上午10:03
 *
 * @author <a href="mailto:caolei@sinosoft.co"> caolei </a>
 * @version 1.0
 */
@NoRepositoryBean
public interface IBaseRepository<T, ID extends Serializable> extends
        JpaRepository<T, ID>, JpaSpecificationExecutor<T> {

    /**
     * Returns all instances of the type with the given IDs.
     *
     * @param ids
     * @return
     */
    Page<T> findAll(Iterable<ID> ids, Pageable pageable);

    /*
     * (non-Javadoc)
     * @see org.springframework.data.repository.CrudRepository#save(java.lang.Object)
     */
    <S extends T> void saveByIgnoreProperties(S entity, Specification<T> specification, String... ignoreProperties);

    /*
     * (non-Javadoc)
     * @see org.springframework.data.repository.CrudRepository#save(java.lang.Object)
     */
    <S extends T> void saveByContainProperties(S entity, Specification<T> specification, String... containProperties);

    /*
     * (non-Javadoc)
     * @see org.springframework.data.repository.CrudRepository#save(java.lang.Object)
     */
    <S extends T> void save(S entity, Specification<T> specification, boolean ignoreNull);

    /*
     * (non-Javadoc)
     * @see org.springframework.data.repository.CrudRepository#save(java.lang.Object)
     */
    <S extends T> void save(S entity, ID key, boolean ignoreNull);
}
